/*日志工具*/
class Log {
    static forceDisplayAll = false;
    static forceHideAllLog = false;

    constructor(name, display = true) {
        this.display = display;

        this.name = name;
        this.show = (Log.forceDisplayAll || this.display) && !Log.forceHideAllLog
    }

    log = (...args) => {
        this.show && this.out('log', ...args)
    }

    warn = (...args) => {
        this.show && this.out('warn', ...args)
    }

    error = (...args) => {
        this.show && this.out('error', ...args)
    }

    out = (type, ...args) => {
        this.name && args.unshift(this.name)
        eval(`console.${type}`)(...args)
    }
}

addListener(Log, 'forceDisplayAll')
addListener(Log, 'forceHideAllLog')


function addListener(object, property) {
    let value = object[property]
    Object.defineProperty(object, property, {
        get() {
            return value;
        },
        set(v) {
            value = v;
            // debugger
            console.log(`[LOG DISPLAY MODE] ${property}: ${value}`);
        },
        enumerable: true,
        configurable: false
    })

}

const logMaker = (name, display = true) => new Log(name, display)

export {Log, logMaker,}
